/*
 * ImDeal.h
 *
 *  Created on: 2017年7月23日
 *      Author: changruowang
 */

#ifndef _ImDeal_H
#define _ImDeal_H

#include "system.h"

#define AngToRad(x) (3.1415926*(x)/180.0)
#define LIMIT( x,min,max ) ( (x) < (min)  ? (min) : ( (x) > (max) ? (max) : (x) ) )
#define K_YAW       30
#define Camera_PIT  150
#define Camera_ROLL 150

typedef enum
{
   front=0,
	 back,
	 left,
	 right,

	Locate_Num,
}Position_Enum;


typedef enum
{
	 N0_Right_Angle=0,
   Top_Left_RightAngle,
	 Top_Right_RightAngle,
	 Bottom_Left_RightAngle,
	 Bottom_Right_RightAngle,
	 Bottom_Left_Right_Circle,
	 Top_Left_Right_Circle,
	 Right_Angle_Num,

}Feature_Point_St;

typedef enum
{
   Point_Zero=0,
	 Point_One,
	 Point_Two,
	 Point_Three,
	 Point_Four,
	 Point_Error,
}Point_Num_St;


typedef enum
{
  Four_Top_Bottom_Letf_Right,

	Three_Top_Letf_Right,
	Three_Top_Bottom_Right,
	Three_Top_Bottom_Letf,
	Three_Bottom_Letf_Right,
	Two_Top_Bottom,
	Two_Top_Left,
	Two_Top_Right,
	Two_Left_Right,
	Two_Bottom_Left,
	Two_Bottom_Right,

	Point_Status_Error,
}Point_Status_St;


typedef  struct
{
	u8 x;
	u8 y;
	u8 x_begin;
	u8 x_end;
	u8 y_begin;
	u8 y_end;
	u8 point_cnt;
}Locate_Point_Info_St;


typedef  struct
{
	float ROLL;
	float PIT;
	float YAW;
	float Height;
}Fly_Status_St;


typedef  struct
{
	u8 mid_x;
	u8 mid_y;
	u8 Last_x;
	u8 Last_y;
	s16 Rotate_Offest;
	s8 Spd_x;
	s8 Spd_y;
	Locate_Point_Info_St  Locate[Locate_Num];
}Point_St;

void Fine_Offest_Rotate(void);
void Deal_Four_Point(void);
void Deal_Two_Point(void);

void ParaInit(void);
void Find_Edge_Point(void);
void Search_Line_Point(u8 HEIGHT,Position_Enum Pos);
void Search_Column_Point(u8 WIDTH,Position_Enum Pos);
void Deal_Three_Point(void);
void Find_Point_Position(void);


u8 Scan_One_Line(u8 HEIGHT,u8* Line_Begin,u8* Line_End,u8 i,Position_Enum Pos);
u8 Edge_Track_Line(u8 x,u8 HEIGHT,u8* Line_Begin,u8* Line_End,u8 i,Position_Enum Pos);
u8 Scan_One_Column(u8 WIDTH,u8* Column_Begin,u8* Column_End,u8 i,Position_Enum Pos);
u8 Edge_Track_Column(u8 x,u8 WIDTH,u8* Column_Begin,u8* Column_End,u8 i,Position_Enum Pos);

void Get_FitImage(void);
void Image_Deal(void);
void Image_Correct(void);

extern double ROLL_Angle,PIT_Angle,YAW_Angle;
extern Point_St Point_t;
extern YesNo_t EN_SendMsgToFmu;
extern Feature_Point_St Feature_Point_E;
extern YesNo_t EN_PID_Calcu;
extern Fly_Status_St Fly_Status_t;
extern YesNo_t EN_Offest_Rotate;
extern uint8_t Image_thr;
extern u8 ImagRecOK;
#endif


